function uploadWithSDK(token, putExtra, config, domain) {
    // 切换tab后进行一些css操作
    // controlTabDisplay("sdk");
    $("#select2").unbind("change").bind("change",function(){
        $.each(this.files,function (index,item) {
            var file = item;
            // eslint-disable-next-line
            var finishedAttr = [];
            // eslint-disable-next-line
            var compareChunks = [];
            var observable;
            if (file) {
                var key = file.name;
                // 添加上传dom面板
                var board = addUploadBoard(file, config, key, "");
                if (!board) {
                    return;
                }
                putExtra.params["x:name"] = key.split(".")[0];
                board.start = true;
                var dom_total = $(board)
                    .find("#totalBar")
                    .children("#totalBarColor");

                // 设置next,error,complete对应的操作，分别处理相应的进度信息，错误信息，以及完成后的操作
                var error = function(err) {
                    board.start = true;
                    $(board).find(".control-upload").text("继续上传");
                    console.log(err);
                    alert("上传出错")
                };

                var complete = function(res) {
                    $(board)
                        .find("#totalBar,.control-upload")
                        .remove();
                    $(board)
                        .find("#success")
                        .html(
                            "<p><strong>Hash：</strong>" +
                            res.hash +
                            "</p>" +
                            "<p><strong>Key：</strong>" +
                            res.key +
                            "</p>"
                        );
                    board.start = "complete";
                    board.name = res.key;
                    var link = $("#qiniuVideo").val();
                    if(link != ""){
                        var v =  link + ',' + res.key
                    }else{
                        var v = res.key;
                    }
                    $("#qiniuVideo").val(v)
                    // if (res.key && res.key.match(/\.(jpg|jpeg|png|gif)$/)) {
                    //     imageDeal(board, res.key, domain);
                    // }
                };

                var next = function(response) {
                    var chunks = response.chunks||[];
                    var total = response.total;
                    // 这里对每个chunk更新进度，并记录已经更新好的避免重复更新，同时对未开始更新的跳过
                    for (var i = 0; i < chunks.length; i++) {
                        if (chunks[i].percent === 0 || finishedAttr[i]){
                            continue;
                        }
                        if (compareChunks[i].percent === chunks[i].percent){
                            continue;
                        }
                        if (chunks[i].percent === 100){
                            finishedAttr[i] = true;
                        }
                        $(board)
                            .find(".fragment-group li")
                            .eq(i)
                            .find("#childBarColor")
                            .css(
                                "width",
                                chunks[i].percent + "%"
                            );
                    }
                    $(board)
                        .find(".speed")
                        .text("进度：" + total.percent + "% ");
                    dom_total.css(
                        "width",
                        total.percent + "%"
                    );
                    compareChunks = chunks;
                };

                var subObject = {
                    next: next,
                    error: error,
                    complete: complete
                };
                var subscription;
                // 调用sdk上传接口获得相应的observable，控制上传和暂停
                observable = qiniu.upload(file, randomString() +Date.now()+".mp3", token, putExtra, config);

                $(board)
                    .find(".control-upload")
                    .on("click", function() {
                        if(board.start){
                            $(this).text("暂停上传");
                            board.start = false;
                            subscription = observable.subscribe(subObject);
                        }else{
                            board.start = true;
                            $(this).text("继续上传");
                            subscription.unsubscribe();
                        }
                    });
                $(board)
                    .find(".control-delete")
                    .on("click", function() {
                        if(typeof(subscription) != 'undefined'){
                            subscription.unsubscribe();
                        }
                        if(board.start == "complete"){
                            var link = $("#qiniuVideo").val().split(',');
                            //删除imgArr中的元素
                            for (var i = 0; i < link.length; i++) {
                                if (link[i] == board.name) {
                                    link.splice(i, 1);
                                    break;
                                }
                            }
                            $("#qiniuVideo").val(link);
                            $.post("/admin/upload/deleteImg",{add:board.name},function(res){

                            })
                        }
                        $(board).remove();
                    });
            }
        })
        $(this).val('');
    })
}

function randomString(len) {
    len = len || 32;
    var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var maxPos = $chars.length;
    var pwd = '';
    for (i = 0; i < len; i++) {
        pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;
}

